<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>#(SiteInfo.siteTitle??)</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="#(ctx)/static/lib/PearAdmin/component/pear/css/pear.css" />
		<link rel="stylesheet" href="#(ctx)/static/lib/PearAdmin/admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="#(ctx)/static/lib/PearAdmin/admin/images/background.svg" style="background-size: cover;">
		<form id="loginForm" class="layui-form" action="javascript:void(0);">
			<div class="layui-form-item">
				<img class="logo" src="#(ctx)/static/lib/PearAdmin/admin/images/logo.png" />
				<div class="title">sitesManager</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="请输入账号" name="userName" lay-verify="required" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input placeholder="请输入密码" name="password" lay-verify="required" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input placeholder="请输入右侧验证码" name="captcha" hover  lay-verify="required" class="code layui-input layui-input-inline"  />
				<img id="captcha" onclick="updateCaptcha()" src="/login/createCaptcha" class="codeImage" />
			</div>
			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登录
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		<script src="#(ctx)/static/lib/PearAdmin/component/layui/layui.js"></script>
		<script src="#(ctx)/static/lib/PearAdmin/component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'popup'], function() {
				let form = layui.form;
				let popup = layui.popup;
				let $ = layui.$;//使用layui内置的jQuery

				// 更新验证码
				window.updateCaptcha = function(){
					$("#captcha").attr("src", "#(ctx)/login/createCaptcha?v=" + Math.random());
					$("#captcha").val("");
				}
				
                // 登录提交
				form.on('submit(login)', function(data) {
					/// 验证
					
					/// 登录
					var $form = $("#loginForm");
					$.post("/login/doLogin", $form.serialize(), function(data){
						console.log(data);
						if("ok"==data.state){
							popup.success("登录成功", function() {
								location.href = data.url;
							});
						} else {
							popup.failure(data.msg, function() {
								location.href = "/login"
							});
						}
					});
					return false;
				});
			})
		</script>
	</body>
</html>
